#include "MainObject.h"
#include "CUtil.h"
#include "CmpMngr.h"
#include <sstream>

MainObject::MainObject()
{
	counter = 0;

	clearCaseFile = false;		

	CCodeCounter* tmp;
	
	tmp = new CCodeCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(DATAFILE		,tmp));
	
	tmp = new CCCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(C_CPP			,tmp));
	
	tmp = new CJavaCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(JAVA			,tmp));
	
	tmp = new CJavaJspCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(JAVA_JSP		,tmp));
	
	tmp = new CCsharpCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(CSHARP			,tmp));
	
	tmp = new CCsharpHtmlCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(CSHARP_HTML	,tmp));
	
	tmp = new CWebCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(WEB			,tmp));
	
	tmp = new CVbCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(VB				,tmp));
	
	tmp = new CVbsPhpCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(VBS_PHP		,tmp));
	
	tmp = new CVbsHtmlCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(VBS_HTML		,tmp));
	
	tmp = new CVbsJspCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(VBS_JSP		,tmp));
	
	tmp = new CVbsAspServerCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(VBS_ASP_S		,tmp));
	
	tmp = new CVbsAspClientCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(VBS_ASP_C		,tmp));
	
	tmp = new CHtmlCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(HTML			,tmp));
	
	tmp = new CHtmlPhpCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(HTML_PHP		,tmp));
	
	tmp = new CHtmlJspCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(HTML_JSP		,tmp));
	
	tmp = new CHtmlAspCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(HTML_ASP		,tmp));
	
	tmp = new CJavascriptCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(JAVASCRIPT		,tmp));
	
	tmp = new CJavascriptPhpCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(JAVASCRIPT_PHP	,tmp));
	
	tmp = new CJavascriptHtmlCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(JAVASCRIPT_HTML,tmp));
	
	tmp = new CJavascriptJspCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(JAVASCRIPT_JSP	,tmp));
	
	tmp = new CJavascriptAspServerCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(JAVASCRIPT_ASP_S,tmp));
	
	tmp = new CJavascriptAspClientCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(JAVASCRIPT_ASP_C,tmp));
	
	tmp = new CPhpCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(PHP			,tmp));
	
	tmp = new CAdaCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(ADA			,tmp));
	
	tmp = new CSqlCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(SQL			,tmp));
	
	tmp = new CPerlCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(PERL			,tmp));

	tmp = new CCsharpAspCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(CS_ASP_S	,tmp));

	tmp = new CCssCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(CSS		,tmp));

	//changes---
	tmp = new CColdfusionCounter;
	CounterForEachLanguage.insert(map<int,CCodeCounter*>::value_type(COLDFUSION	, tmp));

	// Initialize the count vectors, Mod052309VN
	for (map<int,CCodeCounter*>::iterator iter=CounterForEachLanguage.begin();iter!=CounterForEachLanguage.end();iter++)
	{
		iter->second->InitializeCounts();
	}
}

// Method: ResetCounterCounts()
// Description: Reset all count lists (e.g., directive_count, data_name_count, etc.)
//              of the counters to zero. 
// Revision  Date      Author  Modification
// Rev-1     7/5/09		VN     Original authors
void MainObject::ResetCounterCounts() 
{
	for (map<int,CCodeCounter*>::iterator iter=CounterForEachLanguage.begin();iter!=CounterForEachLanguage.end();iter++)
	{
		iter->second->InitializeCounts();
	}
}

MainObject::~MainObject()
{
	for (map<int,CCodeCounter*>::iterator iter = CounterForEachLanguage.begin();iter != CounterForEachLanguage.end(); iter++)
	{
		delete iter->second;
		iter->second = 0;
	}
}

string MainObject::GetLangName(unsigned int class_type) 
{
	if (class_type < CounterForEachLanguage.size())
	{
		return CounterForEachLanguage[class_type]->language_name;
	}
	return DEF_LANG_NAME;
}

// Method: ProcessSourceList(...)
// Description: go through each file and call the relevant counter.
//              passing command line arguments to check for command line  parameter 'dir'. 
// Revision  Date      Author  Modification
// Rev-1     12/02/08  SM, TS	 Original authors
int MainObject::parse_commandLine(int argc, char *argv[])
{
	duplicate_threshold = 0;	//Default Duplicate Files Threshold
	lsloc_truncate = 10000;		//Default LSLOC Maximum characters for truncation (0=no truncation)
	int i=1;
	while (1)
	{
		if (i >= argc)
			break;

		string arg (argv[i]);

		if (arg.compare("-dir") == 0)
		{	//Search for baseline A

			// Command Line parameter 'dir' should be followed by at least two more 
			// arguments - directory name and the names of the extensions to be 
			// searched.
			if (i + 2 > argc)
			{
				string err = "Error: Unable to parse command line args";
				cout << err << endl;
				CUtil::AddError(err);
				return 0;
			}

			i++;
			// Extract the directory name 
			dirnameA = argv[i];

			// Extract the names of the all file extensions to be searched
			for (int j=i+1; j<argc; j++)
			{
				listFilesToBeSearched.push_back(argv[j]);	 		
			}

			if (listFilesToBeSearched.size() == 0) // add all files as the default
			{
				listFilesToBeSearched.push_back("*.*");
			}

			// Support ClearCase files, Mod052409_1VN			
			// return 1;
		}
		else if (arg.compare("-tdup") == 0)
		{
			if (argc >= (i+1))
			{
				double myDup = atof(argv[i+1]);
				if (myDup >= 0 && myDup <= 100)
				{
					duplicate_threshold = myDup;
				}
				else
				{
					show_usage(string(argv[0]));
				}
				i++;
			}
			else
			{
				show_usage(string(argv[0]));
			}
		}
		else if (arg.compare("-trunc") == 0)
		{
			if (argc >= (i+1))
			{
				int myTrunc = atoi(argv[i+1]);
				if (myTrunc >= 0)
				{
					lsloc_truncate = myTrunc;
				}
				else
				{
					show_usage(string(argv[0]));
				}
				i++;
			}
			else
			{
				show_usage(string(argv[0]));
			}
		}
		// Support ClearCase files, Mod052409_1VN
		else if (arg.compare("-cf") == 0)
		{
			clearCaseFile = true;
		}
		else if (arg.compare("-help") == 0)
		{
			show_usage(string(argv[0]));
		}

		i++;
	}
	return 1;
}

/** show_usage 
*    Shows program usage and terminates application.
*    Added parameter -cf to allow ClearCase files, Mod052409_1VN
**/
void MainObject::show_usage (string program, bool do_exit)
{
	cout << "USAGE: " << program << " [-d] [-i1 fileListA.txt] [-i2 fileListB.txt] [-t #] [-tdup #] [-P] " << endl;
	cout << "       [[-dir] <dirA> [dirB] <filespecs>] [-cf] [optional argument]" << endl << endl;
	cout << " -d - if specified will enable the differencing functionality. " << endl;
	cout << " -i1 fileListA.txt - the file name containing the list of files \n     to be used as the 1st baseline in the diff tool." << endl;
	cout << " -i2 fileListB.txt - the file name containing the list of files \n     to be used as the 2nd baseline in the diff tool." << endl;
	cout << " -t # - specify the threshold percentage for a modified line. (DEFAULTS TO 60) " << endl;
	cout << " -tdup # - specify the threshold percentage for duplicated files of same name." << endl;
	cout << "           This specifies the maximum percent difference between two files of the " << endl;
	cout << "              same name in a baseline to be considered duplicates. (DEFAULTS TO 0)" << endl;
	cout << " -trunc # - specify the maximum number of characters allowed in a logical SLOC" << endl;
	cout << "            Additional characters will be truncated. (DEFAULTS TO 10000, use 0 for no truncation) " << endl;
	cout << " -cf - if specified will indicate the target files were retrieved from ClearCase." << endl;
	cout << "       The program will restore the original filename before counting." << endl;
	cout << " -dir - specify the directories and files to be counted. " << endl;
	cout << "        dirA       Name of the directory to be counted. If -d is provided, " << endl;
	cout << "                      dirA is the directory of Baseline A." << endl;
	cout << "        dirB       Name of the directory of Baseline B only if -d is provided." << endl;
	cout << "        filespecs  File specifications, wildcard chars ? * are allowed" << endl;
	cout << "                      For example, *.cpp *.h" << endl;
	//cout << " -P - If this is specified it will perform operations only on Physical Lines of code. " << endl;	
	if (do_exit)
	{
//		cout << "Hit Enter to exit." << endl;
//		cin.get();
		exit(1);
	}
}

int MainObject::MainProcess(int argc, char *argv[])
{
	// ------------------   Duplication Modification -----------------------
	// Check the command line parameters if 'dir' is present in it
	vector <string> listFileNames;

	if (!parse_commandLine(argc,argv))
		show_usage(string(argv[0]));

	if (listFilesToBeSearched.size() != 0)
		CUtil::ListAllFiles(dirnameA, listFilesToBeSearched,listFileNames);

	cout << "Reading source files..."; 
	if (!ReadAllFile(listFileNames))
		return 0;
	cout << ".......................DONE" << endl;

	cout << "Performing files analysis and counting...";
	findDuplicateFiles(SourceFile, duplicateFilesInA1, duplicateFilesInA2);
	ProcessSourceList();

	cout << "Generating results to files...";
	PrintResults(true, "", &duplicateFilesInA2);
	PrintComplexityResults();

	PrintResults(true, "Duplicates-", &duplicateFilesInA2, false);
	PrintComplexityResults(true, "Duplicates-", true);
	PrintDuplicateSummary();
	cout << "................DONE" << endl;

	return 1;
}

// Method: progress(...)
// Description: handle process progress
// -----------------------------------------
// Revision  Date      Author			Modification
// Rev-1     Spring09  Poorak Kashyap	Original author, CSSE
void MainObject::progress(int disp, int count_progress, int sizeo)
{
	if (sizeo == 1)
		cout << ".....100%";
	else
	{
		if (count_progress == 1)
			cout << ".....";
		else
			cout << "\b\b\b\b";
		if (disp < 10)
			cout << "..";
		else if (disp < 100)
			cout << ".";
		cout << disp << "%";
	}
	cout.flush();
}

// Method: ProcessSourceList(...)
// Description: go through each file and call the relevant counter.
// -----------------------------------------
// Revision  Date      Author  Modification
// Rev-1     Summer07  WHH	   Original author, CSSE
// Rev-2     11/10/08  VN      Modified, 11100801VN
void MainObject::ProcessSourceList(bool useListA)
{
	SourceFileList* mySrcFileList = (useListA) ? &SourceFile: &SourceFileB;
	string errList;

	int count_progress = 1;
	int disp = 0;
	int sizeo = 0;
	for (SourceFileList::iterator i = mySrcFileList->begin(); i!= mySrcFileList->end();i++)
	{
		// Handle any exception that may occur un-handled in the counting functions
		// ID: 11100801VN
		try
		{
			sizeo = (int)mySrcFileList->size();
			disp = ((count_progress * 100) / sizeo);
			progress(disp, count_progress, sizeo);
			count_progress++;

			//Examines the file and sets counter to the correct language counter
			DecideLanguage(i->second.file_name);
			i->second.file_type = (counter->classtype == DATAFILE)?DATA:CODE;
			i->second.class_type = counter->classtype;
			counter->CountSLOC(&(i->first),&(i->second));
			if (i->second.trunc_lines > 0)
			{
				stringstream ss;
				ss << "Warning: Truncated ";
				ss << i->second.trunc_lines;
				ss << " line(s) in file (";
				ss << i->second.file_name;
				ss << ")";
				string err = ss.str();
				errList += err + "\n";
				CUtil::AddError(err);
			}

			//if webcounter, insert the separation file into list
			if (counter->classtype == WEB)
			{
				SourceFileList::iterator pos = i;
				pos++;
				map<int,SourceFileElement>* smap = ((CWebCounter*)counter)->GetSeparationMap();
				for (map<int,SourceFileElement>::iterator iter = smap->begin(); iter != smap->end(); iter++)
				{
					if (iter->second.first.size() > 0)
					{
						(useListA) ? SourceFile.insert(pos,iter->second) : SourceFileB.insert(pos,iter->second);
					}
				}
			}
		}
		catch (...)
		{
			string err = "Error: Unable to count file (";
			err += i->second.file_name;
			err += ")";
			errList += err + "\n";
			CUtil::AddError(err);
		}
	}

	if (mySrcFileList->size() > 0)
		cout << "\b\b\b\b\b\b\b\b\b";
	cout << ".....DONE" << endl;
	if (!errList.empty())
		cout << errList;
}

// Method: ReadAllFile(...)
// Description: read all files into mem
// -----------------------------------------
// Revision  Date      Author  Modification
// Rev-1     Summer07  WHH	   Original author, CSSE
// Rev-2     11/10/08  VN      Modified, 11100802VN
// Rev-3     12/02/08  SM, TS  Added an input vector containing a list of files to be counted
//                               the method reads from either inputFileVector or inputFileList
// Rev-4     5/24/09   VN      If the file was created by ClearCase, use the cropped filename
//                               Modification: Mod052409_1VN
// Rev-5     6/30/09   AS	   Modified Mod063009AS.
//                             Notifying users if the source line is longer than MAX_LINE_LENGTH
//                             Making sure the empty file is checked correctly. 
int MainObject::ReadAllFile(StringVector &inputFileVector, string const &inputFileList, bool useListA)
{
	filemap fmap;
	results r;
	r.reset();
	r.lsloc_truncate = lsloc_truncate;
	std::vector<std::string>::iterator itVectorData;
	string dup, clearCaseCroppedFile;
	bool lineTooLong;
	bool isErr = false;
	unsigned int fileclass;

    // If the size of the vector is zero read from the files
	if (inputFileVector.size() == 0 && inputFileList.size() > 0)
	{
	    ifstream fl;
		fl.open(inputFileList.c_str(),ios::in);

		if (!fl.is_open())
		{
			string err = "Error: Unable to open list file (";
			err += inputFileList;
			err += ")";
			cout << endl << err << endl;
			CUtil::AddError(err);
			return 0;
		}
		fl.clear();
		fl.seekg(0,ios::beg);

		while (!(fl.eof()))
		{
			getline(fl,dup);
			inputFileVector.push_back(dup);
			dup = "";
		}

		fl.close();
	}

	// Loop through all the file names extracted from the directory.
	for (itVectorData = inputFileVector.begin(); itVectorData != inputFileVector.end(); itVectorData++)
	{
		dup = *(itVectorData);
		r.e_flag = false;
		r.error_code = "";

		dup = CUtil::TrimString(dup);
		// Handle the @@ from ClearCase, Mod052409_1VN
		if (clearCaseFile)
		{
			clearCaseCroppedFile = CUtil::ConvertClearCaseFile(dup);
			fileclass = DecideLanguage(clearCaseCroppedFile, false);
		}
		else
			fileclass = DecideLanguage(dup, false);
		if (fileclass == DATAFILE)
		{
			// cout << "Warning: file not supported, file skipped (" << dup << ")" << endl;
			continue;
		}
		else
		{
			if (useListA)
				counter->total_filesA++;
			else
				counter->total_filesB++;
		}
		// end of Mod052409_1VN

		// Read all files, not only those having at least 3 chars in filenames
		// 11100802VN, changed dup.size() > 2 to dup.size() > 0
        if (dup.size() > 0)
		{
			fmap.clear();
			string oneline;
            int lineNum = 0;
			ifstream fr(dup.c_str(), ios::in);
			if (!fr.is_open())
			{
				r.e_flag = true;
				r.error_code = "Unable to open file";
				string err = "Error: ";
				err += r.error_code;
				err += " (";
				err += dup;
				err += ")";
				if (!isErr)
					cout << endl;
				isErr = true;
				cout << err << endl;
				CUtil::AddError(err);
				// Fixed a defect causing loop if the last file inaccessible
				// Commented the following two lines, and added else {				
				//getline(fl,dup);
				//continue;
			}
			else 
			{
				//fmap.clear();
				getline(fr,oneline);
				lineTooLong = false;
				while (!fr.eof())
				{
					lineNum++;
					oneline = CUtil::TrimString(oneline);
					if (oneline.length() > MAX_LINE_LENGTH)
					{
						lineTooLong = true;
						break;
					}
					lineElement element(lineNum, oneline);
					fmap.push_back(element);
					getline(fr,oneline);
				}
				fr.clear();
				fr.close();

				//Mod063009AS
				oneline = CUtil::TrimString(oneline);
				if (oneline.length() > MAX_LINE_LENGTH)
				{
					lineTooLong = true;
				}

				if (lineTooLong)
				{
					r.e_flag = true; ////Mod063009AS
					r.error_code = "Line too long";
					string err = "Error: ";
					err += r.error_code;
					err += ", file skipped (";
					err += dup;
					err += ")";
					if (!isErr)
						cout << endl;
					isErr = true;
					cout << err << endl;
					CUtil::AddError(err);
					fmap.clear();  // Don't bother processing the file if an error is just going to be reported.				
				} 
				else if (!oneline.empty())
				{
					lineNum++;
					//oneline = CUtil::TrimString(oneline);
					lineElement element(lineNum, oneline);
					fmap.push_back(element);
				}
				else if (fmap.size() == 0)
				{
					string err = "Warning: File is empty (";
					err += dup;
					err += ")";
					if (!isErr)
						cout << endl;
					isErr = true;
					cout << err << endl;
					CUtil::AddError(err);
				}
			}	//end else
			// If the filename was modified by ClearCase, use the cropped name
			// Mod052409_1VN
			if (clearCaseFile)
			{
				r.file_name = clearCaseCroppedFile;
			}
			else
			{
				r.file_name = dup;
			}

			r.duplicate = false;//Used in Diff Tool
			SourceFileElement s_element(fmap,r);
			//Depending on which source file we are on..
			(useListA) ? SourceFile.push_back(s_element) : SourceFileB.push_back(s_element);			
		}
	}
	return 1;
}

bool MainObject::isSupportedFileExtension(string filename) 
{
	for (map<int,CCodeCounter*>::iterator iter=CounterForEachLanguage.begin();iter!=CounterForEachLanguage.end();iter++)
	{
		if (iter->second->isSupportedFileExtension(filename))
		{
			return true;
		}
	}
	return false;
}

// Method: DecideLanguage(...)
// Description: Determine which counter to be used for the file
//              given via the param. 
// -----------------------------------------
// Revision  Date     Author  Modification
// Rev-1     Fall 07  WHH     Original author
// Rev-2     5/23/09  VN      Modified to handle a defect reported and fixed by Aaron Shumate of NGC - Mod051809VN
//                             The initialization of the count vectors is implemented 
//                             in CCodeCounter::InitializeCounts instead.
// Rev-3     8/03/09  REP     Modified to to return the language classtype, optional setCounter
unsigned int MainObject::DecideLanguage(string file_name, bool setCounter)
{
	bool found = false;
	for (map<int,CCodeCounter*>::iterator iter=CounterForEachLanguage.begin();iter!=CounterForEachLanguage.end();iter++)
	{
		if (iter->second->isSupportedFileExtension(file_name))
		{
			found = true;
			counter = iter->second;
			if (setCounter)
				counter->isPrintKeyword = true;
			break;
		}
	}
	if (!found) counter = CounterForEachLanguage[DATAFILE];
	return counter->classtype;
}


//Rev-1		4/19/09   VN	  Mod041909VN: name the newly created file with its embedding file's filename.
//								The filename is used in the matching function for the comparison purpose
//								new file's filename = embedding file's filename + its default filename
//								(note: the filename contains *.*/ in its name)
//								excludeFiles=true excludes files from list contained in filesToPrint
//								excludeFiles=false includes only files from list contained in filesToPrint
int MainObject::PrintResults(bool useListA, string outputFileNamePrePend, StringVector *filesToPrint, bool excludeFiles)
{
	ofstream* pout;
	map<int,TotalValue> total;
	map<string,WebTotalValue> webtotal;
	unsigned int class_type;
	StringVector::iterator sit;

	SourceFileList::iterator its;
	SourceFileList* mySourceFile = (useListA) ? &SourceFile : &SourceFileB;
	for(its = mySourceFile->begin(); its != mySourceFile->end(); its++)
	{
		if (filesToPrint != NULL)
		{	// restrict based on those files in the filesToPrint list
			sit = filesToPrint->begin();
			while (sit != filesToPrint->end() && its->second.file_name.compare((*sit)) != 0)
			{
				sit++;
			}

			if (excludeFiles)
			{
				if (sit != filesToPrint->end()) continue; // skip the file if in the filesToPrint list
			}
			else
			{
				if (sit == filesToPrint->end()) continue; // skip the file if NOT in the filesToPrint list
			}
		}

		if (its->second.class_type == WEB)
		{
			SourceFileList::iterator startpos = its;
			SourceFileList::iterator endpos = ++startpos;
			for (; endpos!= mySourceFile->end(); endpos++)
			{
				//Mod041909VN: modified to handle the full filename created for embedded code
				//if (endpos->second.file_name[0]!='*') break;
				if (endpos->second.file_name.find("*.*") == string::npos) break;
			}
			string fext = its->second.file_name;
			fext = CUtil::to_lower(fext.substr(fext.find_last_of(".")+1));
			pout = ((CWebCounter*)CounterForEachLanguage[WEB])->getOutputStream(fext,outputFileNamePrePend);

			if (pout == NULL)
			{
				string err = "Error: Unable to create file (";
				err += outputFileNamePrePend;
				if (fext == "php")
					err += "PHP";
				else if (fext == "asp")
					err += "ASP";
				else if (fext == "jsp")
					err += "JSP";
				else
					err += "HTML";
				err += output_file_name;
				err += "). Operation aborted";
				cout << err << endl;
				CUtil::AddError(err);
				return 0;
			}

			if (fext == "php")
			{
				results r_htm;
				results r_js;
				results r_vbs;
				results r_php;
				for (SourceFileList::iterator i = startpos; i!= endpos; i++)
				{
					switch (i->second.class_type)
					{
					case HTML_PHP:
						r_htm = i->second;
						break;
					case JAVASCRIPT_PHP:
						r_js = i->second;
						break;
					case VBS_PHP:
						r_vbs = i->second;
						break;
					case PHP:
						r_php = i->second;
						break;
					}
				}
				r_htm.SLOC_lines[PHY] = r_htm.exec_lines[PHY] + r_htm.data_lines[PHY];
				r_htm.SLOC_lines[LOG] = r_htm.exec_lines[LOG] + r_htm.data_lines[LOG];
				r_htm.total_lines = r_htm.SLOC_lines[PHY] +	r_htm.blank_lines + r_htm.comment_lines;

				r_js.SLOC_lines[PHY] = r_js.exec_lines[PHY] + r_js.data_lines[PHY];
				r_js.SLOC_lines[LOG] = r_js.exec_lines[LOG] + r_js.data_lines[LOG];
				r_js.total_lines = r_js.SLOC_lines[PHY] +	r_js.blank_lines + r_js.comment_lines;

				r_vbs.SLOC_lines[PHY] = r_vbs.exec_lines[PHY] + r_vbs.data_lines[PHY];
				r_vbs.SLOC_lines[LOG] = r_vbs.exec_lines[LOG] + r_vbs.data_lines[LOG];
				r_vbs.total_lines = r_vbs.SLOC_lines[PHY] +	r_vbs.blank_lines + r_vbs.comment_lines;

				r_php.SLOC_lines[PHY] = r_php.directive_lines[PHY] + r_php.exec_lines[PHY] + r_php.data_lines[PHY];
				r_php.SLOC_lines[LOG] = r_php.directive_lines[LOG] + r_php.exec_lines[LOG] + r_php.data_lines[LOG];
				r_php.total_lines = r_php.SLOC_lines[PHY] +	r_php.blank_lines + r_php.comment_lines;

				(*pout).setf(ios::right);
				(*pout).width(6);		(*pout) << (r_htm.blank_lines + r_js.blank_lines + r_vbs.blank_lines + r_php.blank_lines);
 				(*pout) << " |";
				(*pout).width(6);		(*pout) << (r_htm.comment_lines + r_js.comment_lines + r_vbs.comment_lines + r_php.comment_lines);
				(*pout).width(6);		(*pout) << (r_htm.e_comm_lines + r_js.e_comm_lines + r_vbs.e_comm_lines + r_php.e_comm_lines);
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_htm.data_lines[LOG];
				(*pout).width(6);		(*pout) << r_htm.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_js.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_js.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_vbs.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_vbs.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(6);		(*pout) << r_php.directive_lines[LOG];
				(*pout).width(7);		(*pout) << r_php.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_php.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(7);		(*pout) << (r_htm.SLOC_lines[LOG] + r_js.SLOC_lines[LOG] + r_vbs.SLOC_lines[LOG] + r_php.SLOC_lines[LOG]);
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_htm.SLOC_lines[LOG];
				(*pout).width(8);		(*pout) << r_js.SLOC_lines[LOG];
				(*pout).width(8);		(*pout) << r_vbs.SLOC_lines[LOG];
				(*pout).width(6);		(*pout) << r_php.SLOC_lines[LOG];
				(*pout) << " | CODE  ";
				(*pout) << its->second.file_name<<endl;
				(*pout).unsetf(ios::right);

				webtotal[fext].num_of_file++;

				webtotal[fext].total_line += (r_htm.total_lines + r_js.total_lines + r_vbs.total_lines + r_php.total_lines);
				webtotal[fext].blank_line += (r_htm.blank_lines + r_js.blank_lines + r_vbs.blank_lines + r_php.blank_lines);
				webtotal[fext].whole_comment += (r_htm.comment_lines + r_js.comment_lines + r_vbs.comment_lines + r_php.comment_lines);
				webtotal[fext].embed_comment += (r_htm.e_comm_lines + r_js.e_comm_lines + r_vbs.e_comm_lines + r_php.e_comm_lines);
				
				//0:htm 1:js 2:vbs 3:php
				webtotal[fext].phy_decl[0] += r_htm.data_lines[PHY];
				webtotal[fext].phy_instr[0] += r_htm.exec_lines[PHY];
				webtotal[fext].log_decl[0] += r_htm.data_lines[LOG];
				webtotal[fext].log_instr[0] += r_htm.exec_lines[LOG];

				webtotal[fext].phy_decl[1] += r_js.data_lines[PHY];
				webtotal[fext].phy_instr[1] += r_js.exec_lines[PHY];
				webtotal[fext].log_decl[1] += r_js.data_lines[LOG];
				webtotal[fext].log_instr[1] += r_js.exec_lines[LOG];

				webtotal[fext].phy_decl[2] += r_vbs.data_lines[PHY];
				webtotal[fext].phy_instr[2] += r_vbs.exec_lines[PHY];
				webtotal[fext].log_decl[2] += r_vbs.data_lines[LOG];
				webtotal[fext].log_instr[2] += r_vbs.exec_lines[LOG];

				webtotal[fext].phy_direct[3] += r_php.directive_lines[PHY];
				webtotal[fext].phy_decl[3] += r_php.data_lines[PHY];
				webtotal[fext].phy_instr[3] += r_php.exec_lines[PHY];
				webtotal[fext].log_direct[3] += r_php.directive_lines[LOG];
				webtotal[fext].log_decl[3] += r_php.data_lines[LOG];
				webtotal[fext].log_instr[3] += r_php.exec_lines[LOG];
			}
			else if (fext == "jsp")
			{
				results r_htm;
				results r_js;
				results r_vbs;
				results r_java;
				for (SourceFileList::iterator i = startpos; i!= endpos; i++)
				{
					switch (i->second.class_type)
					{
					case HTML_JSP:
						r_htm = i->second;
						break;
					case JAVASCRIPT_JSP:
						r_js = i->second;
						break;
					case VBS_JSP:
						r_vbs = i->second;
						break;
					case JAVA_JSP:
						r_java = i->second;
						break;
					}
				}
				r_htm.SLOC_lines[PHY] = r_htm.exec_lines[PHY] + r_htm.data_lines[PHY];
				r_htm.SLOC_lines[LOG] = r_htm.exec_lines[LOG] + r_htm.data_lines[LOG];
				r_htm.total_lines = r_htm.SLOC_lines[PHY] +	r_htm.blank_lines + r_htm.comment_lines;

				r_js.SLOC_lines[PHY] = r_js.exec_lines[PHY] + r_js.data_lines[PHY];
				r_js.SLOC_lines[LOG] = r_js.exec_lines[LOG] + r_js.data_lines[LOG];
				r_js.total_lines = r_js.SLOC_lines[PHY] +	r_js.blank_lines + r_js.comment_lines;

				r_vbs.SLOC_lines[PHY] = r_vbs.exec_lines[PHY] + r_vbs.data_lines[PHY];
				r_vbs.SLOC_lines[LOG] = r_vbs.exec_lines[LOG] + r_vbs.data_lines[LOG];
				r_vbs.total_lines = r_vbs.SLOC_lines[PHY] +	r_vbs.blank_lines + r_vbs.comment_lines;

				r_java.SLOC_lines[PHY] = r_java.directive_lines[PHY] + r_java.exec_lines[PHY] + r_java.data_lines[PHY];
				r_java.SLOC_lines[LOG] = r_java.directive_lines[LOG] + r_java.exec_lines[LOG] + r_java.data_lines[LOG];
				r_java.total_lines = r_java.SLOC_lines[PHY] +	r_java.blank_lines + r_java.comment_lines;

				(*pout).setf(ios::right);
				(*pout).width(6);		(*pout) << (r_htm.blank_lines + r_js.blank_lines + r_vbs.blank_lines + r_java.blank_lines);
 				(*pout) << " |";
				(*pout).width(6);		(*pout) << (r_htm.comment_lines + r_js.comment_lines + r_vbs.comment_lines + r_java.comment_lines);
				(*pout).width(6);		(*pout) << (r_htm.e_comm_lines + r_js.e_comm_lines + r_vbs.e_comm_lines + r_java.e_comm_lines);
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_htm.data_lines[LOG];
				(*pout).width(6);		(*pout) << r_htm.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_js.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_js.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_vbs.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_vbs.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(6);		(*pout) << r_java.directive_lines[LOG];
				(*pout).width(7);		(*pout) << r_java.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_java.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(7);		(*pout) << (r_htm.SLOC_lines[LOG] + r_js.SLOC_lines[LOG] + r_vbs.SLOC_lines[LOG] + r_java.SLOC_lines[LOG]);
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_htm.SLOC_lines[LOG];
				(*pout).width(8);		(*pout) << r_js.SLOC_lines[LOG];
				(*pout).width(8);		(*pout) << r_vbs.SLOC_lines[LOG];
				(*pout).width(6);		(*pout) << r_java.SLOC_lines[LOG];
				(*pout) << " | CODE  ";
				(*pout) << its->second.file_name<<endl;
				(*pout).unsetf(ios::right);

				webtotal[fext].num_of_file++;

				webtotal[fext].total_line += (r_htm.total_lines + r_js.total_lines + r_vbs.total_lines + r_java.total_lines);
				webtotal[fext].blank_line += (r_htm.blank_lines + r_js.blank_lines + r_vbs.blank_lines + r_java.blank_lines);
				webtotal[fext].whole_comment += (r_htm.comment_lines + r_js.comment_lines + r_vbs.comment_lines + r_java.comment_lines);
				webtotal[fext].embed_comment += (r_htm.e_comm_lines + r_js.e_comm_lines + r_vbs.e_comm_lines + r_java.e_comm_lines);
				
				//0:htm 1:js 2:vbs 3:java
				webtotal[fext].phy_decl[0] += r_htm.data_lines[PHY];
				webtotal[fext].phy_instr[0] += r_htm.exec_lines[PHY];
				webtotal[fext].log_decl[0] += r_htm.data_lines[LOG];
				webtotal[fext].log_instr[0] += r_htm.exec_lines[LOG];

				webtotal[fext].phy_decl[1] += r_js.data_lines[PHY];
				webtotal[fext].phy_instr[1] += r_js.exec_lines[PHY];
				webtotal[fext].log_decl[1] += r_js.data_lines[LOG];
				webtotal[fext].log_instr[1] += r_js.exec_lines[LOG];

				webtotal[fext].phy_decl[2] += r_vbs.data_lines[PHY];
				webtotal[fext].phy_instr[2] += r_vbs.exec_lines[PHY];
				webtotal[fext].log_decl[2] += r_vbs.data_lines[LOG];
				webtotal[fext].log_instr[2] += r_vbs.exec_lines[LOG];

				webtotal[fext].phy_direct[3] += r_java.directive_lines[PHY];
				webtotal[fext].phy_decl[3] += r_java.data_lines[PHY];
				webtotal[fext].phy_instr[3] += r_java.exec_lines[PHY];
				webtotal[fext].log_direct[3] += r_java.directive_lines[LOG];
				webtotal[fext].log_decl[3] += r_java.data_lines[LOG];
				webtotal[fext].log_instr[3] += r_java.exec_lines[LOG];
			}
			else if (fext == "asp")
			{
				results r_htm;
				results r_jsc;
				results r_vbsc;
				results r_jss;
				results r_vbss;
				for (SourceFileList::iterator i = startpos; i!= endpos; i++)
				{
					switch (i->second.class_type)
					{
					case HTML_ASP:
						r_htm = i->second;
						break;
					case JAVASCRIPT_ASP_S:
						r_jss = i->second;
						break;
					case VBS_ASP_S:
						r_vbss = i->second;
						break;
					case JAVASCRIPT_ASP_C:
						r_jsc = i->second;
						break;
					case VBS_ASP_C:
						r_vbsc = i->second;
						break;
					}
				}
				r_htm.SLOC_lines[PHY] = r_htm.exec_lines[PHY] + r_htm.data_lines[PHY];
				r_htm.SLOC_lines[LOG] = r_htm.exec_lines[LOG] + r_htm.data_lines[LOG];
				r_htm.total_lines = r_htm.SLOC_lines[PHY] +	r_htm.blank_lines + r_htm.comment_lines;

				r_jsc.SLOC_lines[PHY] = r_jsc.exec_lines[PHY] + r_jsc.data_lines[PHY];
				r_jsc.SLOC_lines[LOG] = r_jsc.exec_lines[LOG] + r_jsc.data_lines[LOG];
				r_jsc.total_lines = r_jsc.SLOC_lines[PHY] +	r_jsc.blank_lines + r_jsc.comment_lines;

				r_vbsc.SLOC_lines[PHY] = r_vbsc.exec_lines[PHY] + r_vbsc.data_lines[PHY];
				r_vbsc.SLOC_lines[LOG] = r_vbsc.exec_lines[LOG] + r_vbsc.data_lines[LOG];
				r_vbsc.total_lines = r_vbsc.SLOC_lines[PHY] +	r_vbsc.blank_lines + r_vbsc.comment_lines;

				r_jss.SLOC_lines[PHY] = r_jss.directive_lines[PHY] + r_jss.exec_lines[PHY] + r_jss.data_lines[PHY];
				r_jss.SLOC_lines[LOG] = r_jss.directive_lines[LOG] + r_jss.exec_lines[LOG] + r_jss.data_lines[LOG];
				r_jss.total_lines = r_jss.SLOC_lines[PHY] +	r_jss.blank_lines + r_jss.comment_lines;

				r_vbss.SLOC_lines[PHY] = r_vbss.exec_lines[PHY] + r_vbss.data_lines[PHY];
				r_vbss.SLOC_lines[LOG] = r_vbss.exec_lines[LOG] + r_vbss.data_lines[LOG];
				r_vbss.total_lines = r_vbss.SLOC_lines[PHY] +	r_vbss.blank_lines + r_vbss.comment_lines;

				(*pout).setf(ios::right);
				(*pout).width(6);		(*pout) << (r_htm.blank_lines + r_jsc.blank_lines + r_vbsc.blank_lines + r_jss.blank_lines + r_vbss.blank_lines);
 				(*pout) << " |";
				(*pout).width(6);		(*pout) << (r_htm.comment_lines + r_jsc.comment_lines + r_vbsc.comment_lines + r_jss.comment_lines + r_vbss.comment_lines);
				(*pout).width(6);		(*pout) << (r_htm.e_comm_lines + r_jsc.e_comm_lines + r_vbsc.e_comm_lines + r_jss.e_comm_lines + r_vbss.e_comm_lines);
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_htm.data_lines[LOG];
				(*pout).width(6);		(*pout) << r_htm.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_jsc.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_jsc.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_vbsc.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_vbsc.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_jss.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_jss.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_vbss.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_vbss.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(7);		(*pout) << (r_htm.SLOC_lines[LOG] + r_jss.SLOC_lines[LOG] + r_vbss.SLOC_lines[LOG] + r_jsc.SLOC_lines[LOG] + r_vbsc.SLOC_lines[LOG]);
				(*pout) << " |";
				(*pout).width(6);		(*pout) << r_htm.SLOC_lines[LOG];
				(*pout).width(8);		(*pout) << r_jsc.SLOC_lines[LOG];
				(*pout).width(9);		(*pout) << r_vbsc.SLOC_lines[LOG];
				(*pout).width(7);		(*pout) << r_jss.SLOC_lines[LOG];
				(*pout).width(8);		(*pout) << r_vbss.SLOC_lines[LOG];
				(*pout) << " | CODE  ";
				(*pout) << its->second.file_name<<endl;
				(*pout).unsetf(ios::right);

				webtotal[fext].num_of_file++;

				webtotal[fext].total_line += (r_htm.total_lines + r_jsc.total_lines + r_vbsc.total_lines + r_jss.total_lines + r_vbss.total_lines);
				webtotal[fext].blank_line += (r_htm.blank_lines + r_jsc.blank_lines + r_vbsc.blank_lines + r_jss.blank_lines + r_vbss.blank_lines);
				webtotal[fext].whole_comment += (r_htm.comment_lines + r_jsc.comment_lines + r_vbsc.comment_lines + r_jss.comment_lines + r_vbss.comment_lines);
				webtotal[fext].embed_comment += (r_htm.e_comm_lines + r_jsc.e_comm_lines + r_vbsc.e_comm_lines + r_jss.e_comm_lines + r_vbss.e_comm_lines);
				
				//0:htm 1:jsc 2:vbsc 3:jss 4:vbss
				webtotal[fext].phy_decl[0] += r_htm.data_lines[PHY];
				webtotal[fext].phy_instr[0] += r_htm.exec_lines[PHY];
				webtotal[fext].log_decl[0] += r_htm.data_lines[LOG];
				webtotal[fext].log_instr[0] += r_htm.exec_lines[LOG];

				webtotal[fext].phy_decl[1] += r_jsc.data_lines[PHY];
				webtotal[fext].phy_instr[1] += r_jsc.exec_lines[PHY];
				webtotal[fext].log_decl[1] += r_jsc.data_lines[LOG];
				webtotal[fext].log_instr[1] += r_jsc.exec_lines[LOG];

				webtotal[fext].phy_decl[2] += r_vbsc.data_lines[PHY];
				webtotal[fext].phy_instr[2] += r_vbsc.exec_lines[PHY];
				webtotal[fext].log_decl[2] += r_vbsc.data_lines[LOG];
				webtotal[fext].log_instr[2] += r_vbsc.exec_lines[LOG];

				webtotal[fext].phy_decl[3] += r_jss.data_lines[PHY];
				webtotal[fext].phy_instr[3] += r_jss.exec_lines[PHY];
				webtotal[fext].log_decl[3] += r_jss.data_lines[LOG];
				webtotal[fext].log_instr[3] += r_jss.exec_lines[LOG];

				webtotal[fext].phy_decl[4] += r_vbss.data_lines[PHY];
				webtotal[fext].phy_instr[4] += r_vbss.exec_lines[PHY];
				webtotal[fext].log_decl[4] += r_vbss.data_lines[LOG];
				webtotal[fext].log_instr[4] += r_vbss.exec_lines[LOG];
			}
			else
			{
				fext = "htm";
				results r_htm;
				results r_js;
				results r_vbs;
				results r_cs;
				for(SourceFileList::iterator i = startpos; i!= endpos; i++)
				{
					switch (i->second.class_type)
					{
					case HTML:
						r_htm = i->second;
						break;
					case JAVASCRIPT_HTML:
						r_js = i->second;
						break;
					case VBS_HTML:
						r_vbs = i->second;
						break;
					case CSHARP_HTML:
						r_cs = i->second;
						break;
					}
				}
				r_htm.SLOC_lines[PHY] = r_htm.exec_lines[PHY] + r_htm.data_lines[PHY];
				r_htm.SLOC_lines[LOG] = r_htm.exec_lines[LOG] + r_htm.data_lines[LOG];
				r_htm.total_lines = r_htm.SLOC_lines[PHY] +	r_htm.blank_lines + r_htm.comment_lines;

				r_js.SLOC_lines[PHY] = r_js.exec_lines[PHY] + r_js.data_lines[PHY];
				r_js.SLOC_lines[LOG] = r_js.exec_lines[LOG] + r_js.data_lines[LOG];
				r_js.total_lines = r_js.SLOC_lines[PHY] +	r_js.blank_lines + r_js.comment_lines;

				r_vbs.SLOC_lines[PHY] = r_vbs.exec_lines[PHY] + r_vbs.data_lines[PHY];
				r_vbs.SLOC_lines[LOG] = r_vbs.exec_lines[LOG] + r_vbs.data_lines[LOG];
				r_vbs.total_lines = r_vbs.SLOC_lines[PHY] +	r_vbs.blank_lines + r_vbs.comment_lines;

				r_cs.SLOC_lines[PHY] = r_cs.exec_lines[PHY] + r_cs.data_lines[PHY];
				r_cs.SLOC_lines[LOG] = r_cs.exec_lines[LOG] + r_cs.data_lines[LOG];
				r_cs.total_lines = r_cs.SLOC_lines[PHY] +	r_cs.blank_lines + r_cs.comment_lines;

				(*pout).setf(ios::right);
				(*pout).width(6);		(*pout) << (r_htm.blank_lines + r_js.blank_lines + r_vbs.blank_lines + r_cs.blank_lines);
 				(*pout) << " |";
				(*pout).width(6);		(*pout) << (r_htm.comment_lines + r_js.comment_lines + r_vbs.comment_lines + r_cs.comment_lines);
				(*pout).width(6);		(*pout) << (r_htm.e_comm_lines + r_js.e_comm_lines + r_vbs.e_comm_lines + r_cs.e_comm_lines);
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_htm.data_lines[LOG];
				(*pout).width(6);		(*pout) << r_htm.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_js.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_js.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_vbs.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_vbs.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_cs.data_lines[LOG];
				(*pout).width(7);		(*pout) << r_cs.exec_lines[LOG];
				(*pout) << " |";
				(*pout).width(7);		(*pout) << (r_htm.SLOC_lines[LOG] + r_js.SLOC_lines[LOG] + r_vbs.SLOC_lines[LOG] + r_cs.SLOC_lines[LOG]);
				(*pout) << " |";
				(*pout).width(5);		(*pout) << r_htm.SLOC_lines[LOG];
				(*pout).width(8);		(*pout) << r_js.SLOC_lines[LOG];
				(*pout).width(8);		(*pout) << r_vbs.SLOC_lines[LOG];
				(*pout).width(9);		(*pout) << r_cs.SLOC_lines[LOG];
				(*pout) << " | CODE  ";
				(*pout) << its->second.file_name<<endl;
				(*pout).unsetf(ios::right);

				webtotal[fext].num_of_file++;

				webtotal[fext].total_line += (r_htm.total_lines + r_js.total_lines + r_vbs.total_lines + r_cs.total_lines);
				webtotal[fext].blank_line += (r_htm.blank_lines + r_js.blank_lines + r_vbs.blank_lines + r_cs.blank_lines);
				webtotal[fext].whole_comment += (r_htm.comment_lines + r_js.comment_lines + r_vbs.comment_lines + r_cs.comment_lines);
				webtotal[fext].embed_comment += (r_htm.e_comm_lines + r_js.e_comm_lines + r_vbs.e_comm_lines + r_cs.e_comm_lines);
				
				//0:htm 1:js 2:vbs 3:csharp
				webtotal[fext].phy_decl[0] += r_htm.data_lines[PHY];
				webtotal[fext].phy_instr[0] += r_htm.exec_lines[PHY];
				webtotal[fext].log_decl[0] += r_htm.data_lines[LOG];
				webtotal[fext].log_instr[0] += r_htm.exec_lines[LOG];

				webtotal[fext].phy_decl[1] += r_js.data_lines[PHY];
				webtotal[fext].phy_instr[1] += r_js.exec_lines[PHY];
				webtotal[fext].log_decl[1] += r_js.data_lines[LOG];
				webtotal[fext].log_instr[1] += r_js.exec_lines[LOG];

				webtotal[fext].phy_decl[2] += r_vbs.data_lines[PHY];
				webtotal[fext].phy_instr[2] += r_vbs.exec_lines[PHY];
				webtotal[fext].log_decl[2] += r_vbs.data_lines[LOG];
				webtotal[fext].log_instr[2] += r_vbs.exec_lines[LOG];

				webtotal[fext].phy_decl[3] += r_cs.data_lines[PHY];
				webtotal[fext].phy_instr[3] += r_cs.exec_lines[PHY];
				webtotal[fext].log_decl[3] += r_cs.data_lines[LOG];
				webtotal[fext].log_instr[3] += r_cs.exec_lines[LOG];
			}

			//skip the other web language partial file
			its = --endpos;
		}
		else // Other languages other than WEB
		{
			class_type = its->second.class_type;
			pout = CounterForEachLanguage[class_type]->getOutputStream(outputFileNamePrePend);

			if (pout == NULL)
			{
				string err = "Error: Unable to create file (";
				err += outputFileNamePrePend + CounterForEachLanguage[class_type]->language_name + output_file_name;
				err += "). Operation aborted";
				cout << endl << err << endl;
				CUtil::AddError(err);
				return 0;
			}

			if (total.count(class_type) == 0) total.insert(map<int,TotalValue>::value_type(class_type,TotalValue()));

			if (its->second.e_flag)
			{
				(*pout).setf(ios::left);
				(*pout) << " Error: ";
				(*pout).width(65);
				(*pout) << its->second.error_code;
				(*pout) << its->second.file_name << endl << endl;
				(*pout).unsetf(ios::left);
				continue;
			}
			else
			{
				its->second.SLOC_lines[PHY] = its->second.directive_lines[PHY] + its->second.exec_lines[PHY] + its->second.data_lines[PHY];
				its->second.SLOC_lines[LOG] = its->second.directive_lines[LOG] + its->second.exec_lines[LOG] + its->second.data_lines[LOG];
				its->second.total_lines = its->second.SLOC_lines[PHY] +	its->second.blank_lines + its->second.comment_lines;
			}

			total[class_type].num_of_file++;
			
			(*pout).setf(ios::right);
			(*pout).width(6);		(*pout) << its->second.total_lines;
 			(*pout).width(7);		(*pout) << its->second.blank_lines;
			(*pout) << " |";
			(*pout).width(6);		(*pout) << its->second.comment_lines;
			(*pout).width(9);		(*pout) << its->second.e_comm_lines;
			(*pout) << " |";
		    (*pout).width(8);		(*pout) << its->second.directive_lines[LOG];
			(*pout).width(8);		(*pout) << its->second.data_lines[LOG];
			(*pout).width(8);		(*pout) << its->second.exec_lines[LOG];
			(*pout) << " |";
			(*pout).width(7);		(*pout) << its->second.SLOC_lines[LOG];
			(*pout) << (class_type != DATAFILE ? " | CODE" : " | DATA");
			(*pout) << " " << its->second.file_name;
			(*pout) << endl;
			(*pout).unsetf(ios::right);

			//total count for physical lines
			total[class_type].total_line += its->second.total_lines;
			total[class_type].blank_line += its->second.blank_lines;
			total[class_type].whole_comment += its->second.comment_lines;
			total[class_type].embed_comment += its->second.e_comm_lines;
			total[class_type].phy_direct += its->second.directive_lines[PHY];
			total[class_type].phy_decl += its->second.data_lines[PHY];
			total[class_type].phy_instr += its->second.exec_lines[PHY];
			total[class_type].log_direct += its->second.directive_lines[LOG];
			total[class_type].log_decl += its->second.data_lines[LOG];
			total[class_type].log_instr += its->second.exec_lines[LOG];
		}	//if
	}	//for(itt = mySourceFile->begin(); itt != mySourceFile->end(); itt++)

	// Display summary for WEB languages
	for (map<string,WebTotalValue>::iterator itto = webtotal.begin(); itto != webtotal.end(); itto++)
	{
		if (itto->first == "php")
		{
			pout = ((CWebCounter*)CounterForEachLanguage[WEB])->getOutputStream("php",outputFileNamePrePend);
			
			(*pout) << endl;
			(*pout) << string(36,' ')<<"RESULTS SUMMARY"<<endl<<endl;
			(*pout) << "                     |   HTML     |  JS-Clnt    |  VBS-Clnt   |       PHP           |"<<endl;
			(*pout) << " Blank |  Comments   | Word Exec. | Data  Exec. | Data  Exec. | Comp.   Data  Exec. |                 SLOC                | File  SLOC"<<endl;
			(*pout) << " Lines | Whole Embed | LOC  Instr | Decl  Instr | Decl  Instr | Direct. Decl  Instr | Total    HTML JS-Clnt VBS-Clnt  PHP | Type  Definition"<<endl;
			(*pout) << "-------+-------------+------------+-------------+-------------+---------------------+--------+----------------------------+------------------"<<endl;

			(*pout).setf(ios::right);
			(*pout).width(6);		(*pout) << itto->second.blank_line;
			(*pout) << " |";
			(*pout).width(6);		(*pout) << itto->second.whole_comment;
			(*pout).width(6);		(*pout) << itto->second.embed_comment;
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[0];
			(*pout).width(6);		(*pout) << itto->second.phy_instr[0];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[1];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[1];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[2];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[2];
			(*pout) << " |";
			(*pout).width(6);		(*pout) << itto->second.phy_direct[3];
			(*pout).width(7);		(*pout) << itto->second.phy_decl[3];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[3];
			(*pout) << " |";
			(*pout).width(7);		(*pout) << (itto->second.phy_decl[0] + itto->second.phy_instr[0] +
												itto->second.phy_decl[1] + itto->second.phy_instr[1] +
												itto->second.phy_decl[2] + itto->second.phy_instr[2] +
												itto->second.phy_direct[3] + itto->second.phy_decl[3] + itto->second.phy_instr[3]);
			(*pout) << " |";
			(*pout).width(5);		(*pout) << (itto->second.phy_decl[0] + itto->second.phy_instr[0]);
			(*pout).width(8);		(*pout) << (itto->second.phy_decl[1] + itto->second.phy_instr[1]);
			(*pout).width(8);		(*pout) << (itto->second.phy_decl[2] + itto->second.phy_instr[2]);
			(*pout).width(6);		(*pout) << (itto->second.phy_direct[3] + itto->second.phy_decl[3] + itto->second.phy_instr[3]);
			(*pout) << " | CODE  Physical"<<endl;

			(*pout) << string(22,' ');
			(*pout).width(5);		(*pout) << itto->second.log_decl[0];
			(*pout).width(6);		(*pout) << itto->second.log_instr[0];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[1];
			(*pout).width(7);		(*pout) << itto->second.log_instr[1];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[2];
			(*pout).width(7);		(*pout) << itto->second.log_instr[2];
			(*pout) << " |";
			(*pout).width(6);		(*pout) << itto->second.log_direct[3];
			(*pout).width(7);		(*pout) << itto->second.log_decl[3];
			(*pout).width(7);		(*pout) << itto->second.log_instr[3];
			(*pout) << " |";
			(*pout).width(7);		(*pout) << (itto->second.log_decl[0] + itto->second.log_instr[0] +
												itto->second.log_decl[1] + itto->second.log_instr[1] +
												itto->second.log_decl[2] + itto->second.log_instr[2] +
												itto->second.log_direct[3] + itto->second.log_decl[3] + itto->second.log_instr[3]);
			(*pout) << " |";
			(*pout).width(5);		(*pout) << (itto->second.log_decl[0] + itto->second.log_instr[0]);
			(*pout).width(8);		(*pout) << (itto->second.log_decl[1] + itto->second.log_instr[1]);
			(*pout).width(8);		(*pout) << (itto->second.log_decl[2] + itto->second.log_instr[2]);
			(*pout).width(6);		(*pout) << (itto->second.log_direct[3] + itto->second.log_decl[3] + itto->second.log_instr[3]);
			(*pout) << " | CODE  Logical"<<endl;

		}
		else if (itto->first == "jsp")
		{
			pout = ((CWebCounter*)CounterForEachLanguage[WEB])->getOutputStream("jsp",outputFileNamePrePend);
			(*pout) << endl;
			(*pout) << string(36,' ')<<"RESULTS SUMMARY"<<endl<<endl;
			(*pout) << "                     |   HTML     |  JS-Clnt    |  VBS-Clnt   |       Java          |"<<endl;
			(*pout) << " Blank |  Comments   | Word Exec. | Data  Exec. | Data  Exec. | Comp.   Data  Exec. |                 SLOC                | File  SLOC"<<endl;
			(*pout) << " Lines | Whole Embed | LOC  Instr | Decl  Instr | Decl  Instr | Direct. Decl  Instr | Total    HTML JS-Clnt VBS-Clnt Java | Type  Definition"<<endl;
			(*pout) << "-------+-------------+------------+-------------+-------------+---------------------+--------+----------------------------+------------------"<<endl;

			(*pout).setf(ios::right);
			(*pout).width(6);		(*pout) << itto->second.blank_line;
			(*pout) << " |";
			(*pout).width(6);		(*pout) << itto->second.whole_comment;
			(*pout).width(6);		(*pout) << itto->second.embed_comment;
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[0];
			(*pout).width(6);		(*pout) << itto->second.phy_instr[0];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[1];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[1];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[2];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[2];
			(*pout) << " |";
			(*pout).width(6);		(*pout) << itto->second.phy_direct[3];
			(*pout).width(7);		(*pout) << itto->second.phy_decl[3];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[3];
			(*pout) << " |";
			(*pout).width(7);		(*pout) << (itto->second.phy_decl[0] + itto->second.phy_instr[0] +
												itto->second.phy_decl[1] + itto->second.phy_instr[1] +
												itto->second.phy_decl[2] + itto->second.phy_instr[2] +
												itto->second.phy_direct[3] + itto->second.phy_decl[3] + itto->second.phy_instr[3]);
			(*pout) << " |";
			(*pout).width(5);		(*pout) << (itto->second.phy_decl[0] + itto->second.phy_instr[0]);
			(*pout).width(8);		(*pout) << (itto->second.phy_decl[1] + itto->second.phy_instr[1]);
			(*pout).width(8);		(*pout) << (itto->second.phy_decl[2] + itto->second.phy_instr[2]);
			(*pout).width(6);		(*pout) << (itto->second.phy_direct[3] + itto->second.phy_decl[3] + itto->second.phy_instr[3]);
			(*pout) << " | CODE  Physical"<<endl;

			(*pout) << string(22,' ');
			(*pout).width(5);		(*pout) << itto->second.log_decl[0];
			(*pout).width(6);		(*pout) << itto->second.log_instr[0];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[1];
			(*pout).width(7);		(*pout) << itto->second.log_instr[1];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[2];
			(*pout).width(7);		(*pout) << itto->second.log_instr[2];
			(*pout) << " |";
			(*pout).width(6);		(*pout) << itto->second.log_direct[3];
			(*pout).width(7);		(*pout) << itto->second.log_decl[3];
			(*pout).width(7);		(*pout) << itto->second.log_instr[3];
			(*pout) << " |";
			(*pout).width(7);		(*pout) << (itto->second.log_decl[0] + itto->second.log_instr[0] +
												itto->second.log_decl[1] + itto->second.log_instr[1] +
												itto->second.log_decl[2] + itto->second.log_instr[2] +
												itto->second.log_direct[3] + itto->second.log_decl[3] + itto->second.log_instr[3]);
			(*pout) << " |";
			(*pout).width(5);		(*pout) << (itto->second.log_decl[0] + itto->second.log_instr[0]);
			(*pout).width(8);		(*pout) << (itto->second.log_decl[1] + itto->second.log_instr[1]);
			(*pout).width(8);		(*pout) << (itto->second.log_decl[2] + itto->second.log_instr[2]);
			(*pout).width(6);		(*pout) << (itto->second.log_direct[3] + itto->second.log_decl[3] + itto->second.log_instr[3]);
			(*pout) << " | CODE  Logical"<<endl;
		}
		else if (itto->first == "asp")
		{
			pout = ((CWebCounter*)CounterForEachLanguage[WEB])->getOutputStream("asp",outputFileNamePrePend);
			(*pout) << endl;
			(*pout) << string(36,' ')<<"RESULTS SUMMARY"<<endl<<endl;
			(*pout) << "                     |    HTML    |  JS-Clnt    |  VBS-Clnt   |  JS-Svr     |  VBS-Svr    |"<<endl;
			(*pout) << " Blank |  Comments   | Word Exec. | Data  Exec. | Data  Exec. | Data  Exec. | Data  Exec. |               SLOC                            | File  SLOC"<<endl;
			(*pout) << " Lines | Whole Embed | LOC  Instr | Decl  Instr | Decl  Instr | Decl  Instr | Decl  Instr |  Total   HTML JS-Clnt VBS-Clnt JS-Svr VBS-Svr | Type  Definition"<<endl;
			(*pout) << "-------+-------------+------------+-------------+-------------+-------------+-------------+--------+--------------------------------------+------------------"<<endl;

			(*pout).setf(ios::right);
			(*pout).width(6);		(*pout) << itto->second.blank_line;
			(*pout) << " |";
			(*pout).width(6);		(*pout) << itto->second.whole_comment;
			(*pout).width(6);		(*pout) << itto->second.embed_comment;
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[0];
			(*pout).width(6);		(*pout) << itto->second.phy_instr[0];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[1];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[1];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[2];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[2];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[3];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[3];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[4];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[4];
			(*pout) << " |";
			(*pout).width(7);		(*pout) << (itto->second.phy_decl[0] + itto->second.phy_instr[0] +
												itto->second.phy_decl[1] + itto->second.phy_instr[1] +
												itto->second.phy_decl[2] + itto->second.phy_instr[2] +
												itto->second.phy_decl[3] + itto->second.phy_instr[3] +
												itto->second.phy_decl[4] + itto->second.phy_instr[4]);
			(*pout) << " |";
			(*pout).width(5);		(*pout) << (itto->second.phy_decl[0] + itto->second.phy_instr[0]);
			(*pout).width(8);		(*pout) << (itto->second.phy_decl[1] + itto->second.phy_instr[1]);
			(*pout).width(8);		(*pout) << (itto->second.phy_decl[2] + itto->second.phy_instr[2]);
			(*pout).width(8);		(*pout) << (itto->second.phy_decl[3] + itto->second.phy_instr[3]);
			(*pout).width(8);		(*pout) << (itto->second.phy_decl[4] + itto->second.phy_instr[4]);
			(*pout) << " | CODE  Physical"<<endl;

			(*pout) << string(22,' ');
			(*pout).width(5);		(*pout) << itto->second.log_decl[0];
			(*pout).width(6);		(*pout) << itto->second.log_instr[0];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[1];
			(*pout).width(7);		(*pout) << itto->second.log_instr[1];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[2];
			(*pout).width(7);		(*pout) << itto->second.log_instr[2];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[3];
			(*pout).width(7);		(*pout) << itto->second.log_instr[3];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[4];
			(*pout).width(7);		(*pout) << itto->second.log_instr[4];
			(*pout) << " |";
			(*pout).width(7);		(*pout) << (itto->second.log_decl[0] + itto->second.log_instr[0] +
												itto->second.log_decl[1] + itto->second.log_instr[1] +
												itto->second.log_decl[2] + itto->second.log_instr[2] +
												itto->second.log_decl[3] + itto->second.log_instr[3] +
												itto->second.log_decl[4] + itto->second.log_instr[4]);
			(*pout) << " |";
			(*pout).width(5);		(*pout) << (itto->second.log_decl[0] + itto->second.log_instr[0]);
			(*pout).width(8);		(*pout) << (itto->second.log_decl[1] + itto->second.log_instr[1]);
			(*pout).width(8);		(*pout) << (itto->second.log_decl[2] + itto->second.log_instr[2]);
			(*pout).width(8);		(*pout) << (itto->second.log_decl[3] + itto->second.log_instr[3]);
			(*pout).width(8);		(*pout) << (itto->second.log_decl[4] + itto->second.log_instr[4]);
			(*pout) << " | CODE  Logical"<<endl;

		}
		else if (itto->first == "htm")
		{
			pout = ((CWebCounter*)CounterForEachLanguage[WEB])->getOutputStream("htm",outputFileNamePrePend);
			(*pout) << endl;
			(*pout) << string(36,' ')<<"RESULTS SUMMARY"<<endl<<endl;
			(*pout) << "                     |   HTML     |  JS-Clnt    |  VBS-Clnt   |  C#-Clnt    |"<<endl;
			(*pout) << " Blank |  Comments   | Word Exec. | Data  Exec. | Data  Exec. | Data  Exec. |                    SLOC                | File  SLOC"<<endl;
			(*pout) << " Lines | Whole Embed | LOC  Instr | Decl  Instr | Decl  Instr | Decl  Instr | Total    HTML JS-Clnt VBS-Clnt C#-Clnt | Type  Definition"<<endl;
			(*pout) << "-------+-------------+------------+-------------+-------------+-------------+--------+-------------------------------+------------------"<<endl;

			(*pout).setf(ios::right);
			(*pout).width(6);		(*pout) << itto->second.blank_line;
			(*pout) << " |";
			(*pout).width(6);		(*pout) << itto->second.whole_comment;
			(*pout).width(6);		(*pout) << itto->second.embed_comment;
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[0];
			(*pout).width(6);		(*pout) << itto->second.phy_instr[0];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[1];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[1];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[2];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[2];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.phy_decl[3];
			(*pout).width(7);		(*pout) << itto->second.phy_instr[3];
			(*pout) << " |";
			(*pout).width(7);		(*pout) << (itto->second.phy_decl[0] + itto->second.phy_instr[0] +
												itto->second.phy_decl[1] + itto->second.phy_instr[1] +
												itto->second.phy_decl[2] + itto->second.phy_instr[2] +
												itto->second.phy_decl[3] + itto->second.phy_instr[3]);
			(*pout) << " |";
			(*pout).width(5);		(*pout) << (itto->second.phy_decl[0] + itto->second.phy_instr[0]);
			(*pout).width(8);		(*pout) << (itto->second.phy_decl[1] + itto->second.phy_instr[1]);
			(*pout).width(8);		(*pout) << (itto->second.phy_decl[2] + itto->second.phy_instr[2]);
			(*pout).width(9);		(*pout) << (itto->second.phy_decl[3] + itto->second.phy_instr[3]);
			(*pout) << " | CODE  Physical"<<endl;

			(*pout) << string(22,' ');
			(*pout).width(5);		(*pout) << itto->second.log_decl[0];
			(*pout).width(6);		(*pout) << itto->second.log_instr[0];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[1];
			(*pout).width(7);		(*pout) << itto->second.log_instr[1];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[2];
			(*pout).width(7);		(*pout) << itto->second.log_instr[2];
			(*pout) << " |";
			(*pout).width(5);		(*pout) << itto->second.log_decl[3];
			(*pout).width(7);		(*pout) << itto->second.log_instr[3];
			(*pout) << " |";
			(*pout).width(7);		(*pout) << (itto->second.log_decl[0] + itto->second.log_instr[0] +
												itto->second.log_decl[1] + itto->second.log_instr[1] +
												itto->second.log_decl[2] + itto->second.log_instr[2] +
												itto->second.log_decl[3] + itto->second.log_instr[3]);
			(*pout) << " |";
			(*pout).width(5);		(*pout) << (itto->second.log_decl[0] + itto->second.log_instr[0]);
			(*pout).width(8);		(*pout) << (itto->second.log_decl[1] + itto->second.log_instr[1]);
			(*pout).width(8);		(*pout) << (itto->second.log_decl[2] + itto->second.log_instr[2]);
			(*pout).width(9);		(*pout) << (itto->second.log_decl[3] + itto->second.log_instr[3]);
			(*pout) << " | CODE  Logical"<<endl;
		}

		// Display statistics
		(*pout) << endl << "Number of files successfully accessed........................ ";
		(*pout).width(5);		(*pout) << itto->second.num_of_file;
		(*pout) << " out of ";
		if (filesToPrint != NULL)
		{
			if (excludeFiles)
			{
				if (useListA)
					(*pout) << CounterForEachLanguage[WEB]->total_filesA - filesToPrint->size() << endl;
				else
					(*pout) << CounterForEachLanguage[WEB]->total_filesB - filesToPrint->size() << endl;
			}
			else
				(*pout) << filesToPrint->size();
		}
		else if (useListA)
			(*pout) << CounterForEachLanguage[WEB]->total_filesA << endl;
		else
			(*pout) << CounterForEachLanguage[WEB]->total_filesB << endl;

		(*pout) << endl << "Ratio of Physical to Logical SLOC............................ ";

		int tlsloc = itto->second.log_decl[0] + itto->second.log_instr[0] +
			itto->second.log_decl[1] + itto->second.log_instr[1] +
			itto->second.log_decl[2] + itto->second.log_instr[2] +
			itto->second.log_decl[3] + itto->second.log_instr[3];
		if (tlsloc > 0)
		{
			int tpsloc = itto->second.phy_decl[0] + itto->second.phy_instr[0] +
				itto->second.phy_decl[1] + itto->second.phy_instr[1] +
				itto->second.phy_decl[2] + itto->second.phy_instr[2] +
				itto->second.phy_decl[3] + itto->second.phy_instr[3];
			float tslocrat = (float)tpsloc / (float)tlsloc;
			(*pout).setf(ios::fixed,ios::floatfield);
			(*pout).width(8);
			(*pout).precision(2);
			(*pout) << tslocrat << endl;
			(*pout).unsetf(ios::floatfield);
		}
		else
			(*pout) << "    NA" << endl;
	}

	// Display summary for other languages, other than WEB
	for (map<int,TotalValue>::iterator itto = total.begin(); itto != total.end(); itto++)
	{
		pout = CounterForEachLanguage[itto->first]->getOutputStream(outputFileNamePrePend);
		(*pout) << endl;
		(*pout) << string(36,' ')<<"RESULTS SUMMARY"<<endl<<endl;
		(*pout) << "   Total   Blank |      Comments     |  Compiler  Data    Exec.  |  Number  |          File  SLOC"<<endl;
		(*pout) << "   Lines   Lines |   Whole  Embedded |  Direct.   Decl.   Instr. | of Files |   SLOC   Type  Definition"<<endl;
		(*pout) << string(110,'-')<<endl;

		(*pout).setf(ios::right);
		(*pout).width(8);		(*pout) << itto->second.total_line;
		(*pout).width(8);		(*pout) << itto->second.blank_line;
		(*pout) << " |";
		(*pout).width(8);		(*pout) << itto->second.whole_comment;
		(*pout).width(10);		(*pout) << itto->second.embed_comment;
		(*pout) << " |";
		(*pout).width(9);		(*pout) << itto->second.phy_direct;
		(*pout).width(8);		(*pout) << itto->second.phy_decl;
		(*pout).width(9);		(*pout) << itto->second.phy_instr;
		(*pout) << " |";
		(*pout).width(7);		(*pout) << itto->second.num_of_file;
		(*pout) << "   |";
		(*pout).width(8);		(*pout) << itto->second.phy_direct + itto->second.phy_decl + itto->second.phy_instr;
		(*pout) << "  CODE  Physical"<<endl;

//		(*pout) << string(38,' ');
		(*pout).setf(ios::right);
		(*pout).width(8);		(*pout) << itto->second.total_line;
		(*pout).width(8);		(*pout) << itto->second.blank_line;
		(*pout) << " |";
		(*pout).width(8);		(*pout) << itto->second.whole_comment;
		(*pout).width(10);		(*pout) << itto->second.embed_comment;
		(*pout) << " |";

		(*pout).width(9);		(*pout) << itto->second.log_direct;
		(*pout).width(8);		(*pout) << itto->second.log_decl;
		(*pout).width(9);		(*pout) << itto->second.log_instr;
		(*pout) << " |";
		(*pout).width(7);		(*pout) << itto->second.num_of_file;
		(*pout) << "   |";
		(*pout).width(8);		(*pout) << itto->second.log_direct + itto->second.log_decl + itto->second.log_instr;
		(*pout) << "  CODE  Logical"<<endl;

		// Display statistics
		(*pout) << endl << "Number of files successfully accessed........................ ";
		(*pout).width(5);		(*pout) << itto->second.num_of_file;
		(*pout) << " out of ";
		if (filesToPrint != NULL)
		{
			if (excludeFiles)
			{
				if (useListA)
					(*pout) << CounterForEachLanguage[itto->first]->total_filesA - filesToPrint->size() << endl;
				else
					(*pout) << CounterForEachLanguage[itto->first]->total_filesB - filesToPrint->size() << endl;
			}
			else
				(*pout) << filesToPrint->size();
		}
		else if (useListA)
			(*pout) << CounterForEachLanguage[itto->first]->total_filesA << endl;
		else
			(*pout) << CounterForEachLanguage[itto->first]->total_filesB << endl;

		(*pout) << endl << "Ratio of Physical to Logical SLOC............................ ";

		int tlsloc = itto->second.log_direct + itto->second.log_decl + itto->second.log_instr;
		if (tlsloc > 0)
		{
			int tpsloc = itto->second.phy_direct + itto->second.phy_decl + itto->second.phy_instr;
			float tslocrat = (float)tpsloc / (float)tlsloc;
			(*pout).setf(ios::fixed,ios::floatfield);
			(*pout).width(8);
			(*pout).precision(2);
			(*pout) << tslocrat << endl;
			(*pout).unsetf(ios::floatfield);
		}
		else
			(*pout) << "    NA" << endl;
	}

	string dots = "........................";
	IntPairVector::iterator idirc;
	IntPairVector::iterator idatc;
	IntPairVector::iterator iexec;
	StringVector::iterator idir;
	StringVector::iterator idat;
	StringVector::iterator iexe;
	string web_fext;

	// Display keywords counts
	for (map<int,CCodeCounter*>::iterator iter = ++CounterForEachLanguage.begin(); iter != CounterForEachLanguage.end(); iter++)
	{
		if (total.count(iter->second->classtype) == 0)
		{
			if (iter->second->isPrintKeyword)
			{
				unsigned int ty = iter->second->classtype;
				if (ty == PHP || ty == HTML_PHP || ty == JAVASCRIPT_PHP || ty == VBS_PHP)
				{
					pout = ((CWebCounter*)CounterForEachLanguage[WEB])->getOutputStream("php",outputFileNamePrePend);
				}
				else if (ty == JAVA_JSP || ty == HTML_JSP || ty == JAVASCRIPT_JSP || ty == VBS_JSP)
				{
					pout = ((CWebCounter*)CounterForEachLanguage[WEB])->getOutputStream("jsp",outputFileNamePrePend);
				}
				else if (ty == HTML_ASP || ty == JAVASCRIPT_ASP_C || ty == VBS_ASP_C || ty == JAVASCRIPT_ASP_S || ty == VBS_ASP_S)
				{
					pout = ((CWebCounter*)CounterForEachLanguage[WEB])->getOutputStream("asp",outputFileNamePrePend);
				}
				else if (ty == HTML || ty == JAVASCRIPT_HTML || ty == VBS_HTML || ty == CSHARP_HTML)
				{
					pout = ((CWebCounter*)CounterForEachLanguage[WEB])->getOutputStream("htm",outputFileNamePrePend);
				}
				else
				{
					continue;
				}
			}
			else
			{
				continue;
			}
		}
		else
		{
			pout = CounterForEachLanguage[iter->second->classtype]->getOutputStream(outputFileNamePrePend);
		}

		(*pout) << endl;
		(*pout) << string(32,' ')<< "TOTAL OCCURRENCES OF " << iter->second->language_name << " KEYWORDS" << endl;
		(*pout) << "--------------------------------------------------------------------------------------------------------------" << endl;
		(*pout) << "   Compiler Directives                   Data Keywords                        Executable Keywords" << endl;
		(*pout).setf(ios::right);
		idirc = iter->second->directive_count.begin();
		idatc = iter->second->data_name_count.begin();
		iexec = iter->second->exec_name_count.begin();
		idir = iter->second->directive.begin();
		idat = iter->second->data_name_list.begin();
		iexe = iter->second->exec_name_list.begin();

		while ( (idir != iter->second->directive.end()) || (idat != iter->second->data_name_list.end()) ||
			(iexe != iter->second->exec_name_list.end()) )
		{
			if (idir != iter->second->directive.end())
			{
				(*pout) << ' ' << *idir << dots.substr(idir->length());
				(*pout).width(7);
				if (filesToPrint != NULL && !excludeFiles)
					(*pout) << (*idirc).second;
				else
					(*pout) << (*idirc).first;
				idir++;
				idirc++;
			}
			else
			{
				(*pout) << "                                ";
			}
			(*pout) << "     ";

			if (idat != iter->second->data_name_list.end())
			{
				(*pout) << ' ' << *idat << dots.substr(idat->length());
				(*pout).width(7);
				if (filesToPrint != NULL && !excludeFiles)
					(*pout) << (*idatc).second;
				else
					(*pout) << (*idatc).first;
				idat++;
				idatc++;
			}
			else
			{
				(*pout) << "                               ";
			}
			(*pout) << "     ";

			if (iexe != iter->second->exec_name_list.end())
			{
				(*pout) << ' ' << *iexe << dots.substr(iexe->length());
				(*pout).width(7);
				if (filesToPrint != NULL && !excludeFiles)
					(*pout) << (*iexec).second;
				else
					(*pout) << (*iexec).first;
				iexe++;
				iexec++;
			}
			else
			{
				(*pout) << "                               ";
			}
			(*pout) << endl;
		}
	}

	//close all file
	for (map<int,CCodeCounter*>::iterator iter=CounterForEachLanguage.begin();iter!=CounterForEachLanguage.end();iter++)
	{
		iter->second->closeOutputStream();
	}
/*
Code Commented by VN, Dec 2008. Display the output of each language, we don't need to show the aggregated 
outputs (in one file) for all languages.
//========================== Writing all results into one file ========================================================
	ofstream outfile;
	//Prepend baseline Name here....

	outputFileNamePrePend.append(output_file_name_old);
	outfile.open(outputFileNamePrePend.c_str(), ios::out);
	results tot[2];
	int num_files[2];

	num_files[DATA] = 0;
	num_files[CODE] = 0;
	//bzero(&tot,sizeof(tot));
	//memset(&tot,0,sizeof(tot));
	//initialize total counts
	for(int k=0; k<2; k++) {
		tot[k].blank_lines=0;
		tot[k].comment_lines=0;
		tot[k].e_comm_lines=0;
		tot[k].directive_lines[PHY]=0;
		tot[k].data_lines[PHY]=0;
		tot[k].exec_lines[PHY]=0;
		tot[k].SLOC_lines[PHY]=0;
		tot[k].directive_lines[LOG]=0;
		tot[k].data_lines[LOG]=0;
		tot[k].exec_lines[LOG]=0;
		tot[k].SLOC_lines[LOG]=0;
		tot[k].total_lines=0;
	}

	outfile << "\n - SOURCE LINES OF CODE COUNTING PROGRAM";
		outfile << "\n - Unified CodeCount Tool(Fall 2007)\n\n";
		outfile << "                                    <The Results for each Files>\n\n";
		outfile << " Total  Blank |    Comments   | Compiler  Data   Exec.  | SLOC |  MODE  | File | File\n";
		outfile << " Lines  Lines | Whole Embedded| Direct.   Decl.  Instr. |      |        | Type | Name\n";
		outfile << "------------------------------------------------------------------------------------------------------------\n";

		//print counts for each files
		SourceFileList::iterator itt;

		for(itt = mySourceFile->begin(); itt != mySourceFile->end(); itt++)
		{
			if(itt->second.class_type == WEB)
			{
				outfile<<"                                                                                 "<<itt->second.file_name<<endl;
				num_files[CODE]++;
			}
			else
			{
				if(itt->second.e_flag)
				{
					outfile.setf(ios::left);
					outfile << " Error: ";
					outfile.width(80);
					outfile << itt->second.error_code;
					outfile << itt->second.file_name << endl << endl;
					outfile.unsetf(ios::left);
					continue;
				}
				else
				{
					itt->second.SLOC_lines[PHY] = itt->second.directive_lines[PHY] + itt->second.exec_lines[PHY] + itt->second.data_lines[PHY];
					itt->second.SLOC_lines[LOG] = itt->second.directive_lines[LOG] + itt->second.exec_lines[LOG] + itt->second.data_lines[LOG];
					itt->second.total_lines = itt->second.SLOC_lines[PHY] +	itt->second.blank_lines + itt->second.comment_lines;
				}

				if(itt->second.file_type ==  DATA)
					num_files[DATA]++;
				else if(itt->second.file_name[0] != '*')
					num_files[CODE]++;

				for(int i=PHY; i <= LOG ; i++) {
					outfile.setf(ios::right);

				//	tot[(*itt).file_type].file_name = (*itt).file_name;
				//	tot[(*itt).file_type].file_type = (*itt).file_type;


					if(i==PHY) {
						outfile.width(6);		outfile << itt->second.total_lines;
			 			outfile.width(7);		outfile << itt->second.blank_lines;
						outfile.width(8);		outfile << itt->second.comment_lines;
						outfile.width(9);		outfile << itt->second.e_comm_lines;
			    		outfile.width(9);		outfile << itt->second.directive_lines[i];
						outfile.width(6);		outfile << itt->second.data_lines[i];
						outfile.width(9);		outfile << itt->second.exec_lines[i];

						outfile.width(8);	outfile << itt->second.SLOC_lines[PHY];
						outfile.setf(ios::left); outfile.width(8);	outfile << "  Physical";
						outfile.width(6);	itt->second.file_type ==  DATA ? outfile << "DATA" : outfile << "CODE";
						outfile.setf(ios::left); outfile.width(3);
						if(itt->second.file_name[0] != '*')
						{
							outfile << " " << itt->second.file_name;
						}
						else
						{
							outfile << "     " << WEB_LANGUAGE_NAME[itt->second.class_type];
						}

						//total count for physical lines
						tot[itt->second.file_type].total_lines += itt->second.total_lines;
						tot[itt->second.file_type].blank_lines += itt->second.blank_lines;
						tot[itt->second.file_type].comment_lines += itt->second.comment_lines;
						tot[itt->second.file_type].e_comm_lines += itt->second.e_comm_lines;
						tot[itt->second.file_type].directive_lines[i] += itt->second.directive_lines[i];
						tot[itt->second.file_type].data_lines[i] += itt->second.data_lines[i];
						tot[itt->second.file_type].exec_lines[i] += itt->second.exec_lines[i];
						tot[itt->second.file_type].SLOC_lines[i] += itt->second.SLOC_lines[i];


					}else if(i==LOG){
						outfile.width(39);		outfile << itt->second.directive_lines[i];
						outfile.width(6);		outfile << itt->second.data_lines[i];
						outfile.width(9);		outfile << itt->second.exec_lines[i];

						outfile.width(8);	outfile << itt->second.SLOC_lines[LOG];
						outfile.setf(ios::left); outfile.width(8);	outfile << "  Logical";

						// total count for logical lines
						tot[itt->second.file_type].directive_lines[i] += itt->second.directive_lines[i];
						tot[itt->second.file_type].data_lines[i] += itt->second.data_lines[i];
						tot[itt->second.file_type].exec_lines[i] += itt->second.exec_lines[i];
						tot[itt->second.file_type].SLOC_lines[i] += itt->second.SLOC_lines[i];


					}
					outfile << "\n";
					outfile.unsetf(ios::right);

					// count ing total

				}
				outfile << "\n";
			}
		}//for

	outfile << "-----------------------------------------------<totals>-----------------------------------------------------\n";
	for(int x=CODE; x<=DATA; x++) {
			for(int y=PHY; y<=LOG ; y++) {
				outfile.setf(ios::right);


				if ( y == PHY ) {
				outfile.width(6); outfile << tot[x].total_lines;
				outfile.width(7); outfile << tot[x].blank_lines;
				outfile.width(8); outfile << tot[x].comment_lines;
				outfile.width(9); outfile << tot[x].e_comm_lines;
				outfile.width(9); outfile << tot[x].directive_lines[y];
				} else {
				outfile.width(39); outfile << tot[x].directive_lines[y];
				}
				outfile.width(6); outfile << tot[x].data_lines[y];
				outfile.width(9); outfile << tot[x].exec_lines[y];


				outfile.width(8); outfile << tot[x].SLOC_lines[y];
				if ( y == PHY) {
					outfile.setf(ios::left); outfile.width(10); outfile << "Physical";
					outfile.width(6); x == CODE ? outfile << "CODE" : outfile << "DATA";
					outfile.width(5); outfile << num_files[x] << " file(s)";

				} else {
					outfile.setf(ios::left); outfile.width(9); outfile << "Logical";
				}
				
				outfile << endl;
				outfile.unsetf(ios::right);
			}
	}

	for (map<int,CCodeCounter*>::iterator iter = ++CounterForEachLanguage.begin(); iter != CounterForEachLanguage.end(); iter++)
	{
		if(iter->second->classtype == WEB) continue;
		if(iter->second->isPrintKeyword)
		{
			outfile << "------------------------------------------------------------------------------------------------------------" << endl;
			outfile << "Total occurrences of these " << iter->second->language_name << " Keywords :" << endl;
			outfile << "   Compiler Directives                Data Keywords                      Executable Keywords" << endl;
			outfile.setf(ios::right);
			idirc = iter->second->directive_count.begin();
			idatc = iter->second->data_name_count.begin();
			iexec = iter->second->exec_name_count.begin();
			idir = iter->second->directive.begin();
			idat = iter->second->data_name_list.begin();
			iexe = iter->second->exec_name_list.begin();

			while( (idir != iter->second->directive.end()) || (idat != iter->second->data_name_list.end()) || (iexe != iter->second->exec_name_list.end()) )
			{
				if (idir != iter->second->directive.end())
				{
					outfile << ' ' << *idir << dots.substr(idir->length());
					outfile.width(7);
					outfile << *idirc;
					idir++;
					idirc++;
				}
				else
				{
					outfile << "                           ";
				}
				outfile << "        ";
				
				if (idat != iter->second->data_name_list.end())
				{
					outfile << ' ' << *idat << dots.substr(idat->length());
					outfile.width(7);
					outfile << *idatc;
					idat++;
					idatc++;
				}
				else
				{
					outfile << "                           ";
				}
				outfile << "        ";
				
				if (iexe != iter->second->exec_name_list.end())
				{
					outfile << ' ' << *iexe << dots.substr(iexe->length());
					outfile.width(7);
					outfile << *iexec;
					iexe++;
					iexec++;
				}
				else
				{
					outfile << "                           ";
				}
				outfile << endl;
			}
		}
	}

	outfile.close();
*/

	return 1;
}

// Print complexity results.
int MainObject::PrintComplexityResults(bool useListA, string outputFileNamePrePend, bool printDuplicates) 
{
	/*****************************************************************************************************/
	/* MMG : Write to the complexity count file															 */
	/*****************************************************************************************************/
	if (useListA)
	{
		if (printDuplicates && duplicateFilesInA2.size() < 1)
			return 1;
	}
	else
	{
		if (printDuplicates && duplicateFilesInB2.size() < 1)
			return 1;
	}

	string dots = "......................";
	string COL_SP = "                           ";
	string SP_BW_COL = "    ";
	SourceFileList* mySourceFile = (useListA) ? &SourceFile : &SourceFileB;

	StringVector::iterator imath;  // Math
	StringVector::iterator itrig;  // trig
	StringVector::iterator ilog;   // logarithmic
	StringVector::iterator icalc;  // calculation
	StringVector::iterator icond;  // Conditionals
	StringVector::iterator ilogic; // logical
	StringVector::iterator ipreproc; // Preprocessor
	StringVector::iterator iassign; // Assign
	StringVector::iterator ipointer; // pointers
	IntPairVector::iterator imathc;		
	IntPairVector::iterator itrigc; 
	IntPairVector::iterator ilogc;
	IntPairVector::iterator icalcc;
	IntPairVector::iterator icondc;
	IntPairVector::iterator ilogicc;
	IntPairVector::iterator ipreprocc; 
	IntPairVector::iterator iassignc; 
	IntPairVector::iterator ipointerc; 
	results cmplxTotal;

	cmplxTotal.cmplx_math_lines = 0;
	cmplxTotal.cmplx_trig_lines = 0;
	cmplxTotal.cmplx_logrithm_lines = 0;
	cmplxTotal.cmplx_calc_lines = 0;
	cmplxTotal.cmplx_cond_lines = 0;
	cmplxTotal.cmplx_logic_lines = 0;
	cmplxTotal.cmplx_prepoc_lines = 0;
	cmplxTotal.cmplx_assign_lines = 0;
	cmplxTotal.cmplx_pointer_lines = 0;

	ofstream cplxOutputFile;
	
	string cplxOutputFileName (outputFileNamePrePend);

	cplxOutputFileName.append(output_file_cplx);

	cplxOutputFile.open(cplxOutputFileName.c_str(), ios::out);

	if (!cplxOutputFile.is_open())
	{
		string err = "Error: Unable to create file (";
		err += cplxOutputFileName;
		err += "). Operation aborted";
		cout << endl << err << endl;
		CUtil::AddError(err);
		return 0;
	}
	
	CUtil::PrintFileHeader(cplxOutputFile, "COMPLEXITY COUNT RESULTS");

	cplxOutputFile << " Math    Trig   Logrithm  Calculation     Cond.   Logical   Preproc.  Assignment   Pointer   |    FileName      \n";
	cplxOutputFile << " --------------------------------------------------------------------------------------------------------------------------------\n";
		
	// print counts for each file
	SourceFileList::iterator itt2;

	for (itt2 = mySourceFile->begin(); itt2 != mySourceFile->end(); itt2++)
	{
		if ((!printDuplicates && !itt2->second.duplicate) || (printDuplicates && itt2->second.duplicate))
		{
			cplxOutputFile.width(5);	cplxOutputFile << itt2->second.cmplx_math_lines;
			cplxOutputFile.width(8);	cplxOutputFile << itt2->second.cmplx_trig_lines;
			cplxOutputFile.width(11);	cplxOutputFile << itt2->second.cmplx_logrithm_lines;
			cplxOutputFile.width(11);	cplxOutputFile << itt2->second.cmplx_calc_lines;
			cplxOutputFile.width(11);	cplxOutputFile << itt2->second.cmplx_cond_lines;
			cplxOutputFile.width(11);	cplxOutputFile << itt2->second.cmplx_logic_lines;
			cplxOutputFile.width(11);	cplxOutputFile << itt2->second.cmplx_prepoc_lines;
			cplxOutputFile.width(11);	cplxOutputFile << itt2->second.cmplx_assign_lines;
			cplxOutputFile.width(11);	cplxOutputFile << itt2->second.cmplx_pointer_lines;
			cplxOutputFile << "         " << itt2->second.file_name << endl;

			cmplxTotal.cmplx_math_lines += itt2->second.cmplx_math_lines;
			cmplxTotal.cmplx_trig_lines += itt2->second.cmplx_trig_lines;
			cmplxTotal.cmplx_logrithm_lines += itt2->second.cmplx_logrithm_lines;
			cmplxTotal.cmplx_calc_lines += itt2->second.cmplx_calc_lines;
			cmplxTotal.cmplx_cond_lines += itt2->second.cmplx_cond_lines;
			cmplxTotal.cmplx_logic_lines += itt2->second.cmplx_logic_lines;
			cmplxTotal.cmplx_prepoc_lines += itt2->second.cmplx_prepoc_lines;
			cmplxTotal.cmplx_assign_lines += itt2->second.cmplx_assign_lines;
			cmplxTotal.cmplx_pointer_lines += itt2->second.cmplx_pointer_lines;
		}
	}

	cplxOutputFile << "\n\n -----------------------------------------------< totals >-------------------------------------------------------------------\n\n";

	cplxOutputFile.width(5);	cplxOutputFile << cmplxTotal.cmplx_math_lines;
	cplxOutputFile.width(8);	cplxOutputFile << cmplxTotal.cmplx_trig_lines;
	cplxOutputFile.width(11);	cplxOutputFile << cmplxTotal.cmplx_logrithm_lines;
	cplxOutputFile.width(11);	cplxOutputFile << cmplxTotal.cmplx_calc_lines;
	cplxOutputFile.width(11);	cplxOutputFile << cmplxTotal.cmplx_cond_lines;
	cplxOutputFile.width(11);	cplxOutputFile << cmplxTotal.cmplx_logic_lines;
	cplxOutputFile.width(11);	cplxOutputFile << cmplxTotal.cmplx_prepoc_lines;
	cplxOutputFile.width(11);	cplxOutputFile << cmplxTotal.cmplx_assign_lines;
	cplxOutputFile.width(11);	cplxOutputFile << cmplxTotal.cmplx_pointer_lines;

	cplxOutputFile << "\n\n";

	for (map<int,CCodeCounter*>::iterator iter = ++CounterForEachLanguage.begin(); iter != CounterForEachLanguage.end(); iter++)
	{		
		imath = iter->second->math_func_list.begin(); // MMG
		itrig = iter->second->trig_func_list.begin();
		ilog = iter->second->log_func_list.begin();
		icalc = iter->second->cmplx_calc_list.begin();
		icond = iter->second->cmplx_cond_list.begin();
		ilogic = iter->second->cmplx_logic_list.begin();
		ipreproc = iter->second->cmplx_preproc_list.begin();
		iassign = iter->second->cmplx_assign_list.begin();
		ipointer = iter->second->cmplx_pointer_list.begin(); //RST

		imathc = iter->second->math_func_count.begin();
		itrigc = iter->second->trig_func_count.begin();
		ilogc = iter->second->log_func_count.begin();
		icalcc = iter->second->cmplx_calc_count.begin();
		icondc = iter->second->cmplx_cond_count.begin();
		ilogicc = iter->second->cmplx_logic_count.begin();
		ipreprocc = iter->second->cmplx_preproc_count.begin(); 
		iassignc = iter->second->cmplx_assign_count.begin(); // End MMG
		ipointerc = iter->second->cmplx_pointer_count.begin(); // RST
		
		if ( (imathc != iter->second->math_func_count.end()) || 
				(itrigc != iter->second->trig_func_count.end()) ||
				(ilogc  != iter->second->log_func_count.end()) ||
				(icalcc != iter->second->cmplx_calc_count.end()) ||
				(icondc != iter->second->cmplx_cond_count.end()) ||
				(ilogicc != iter->second->cmplx_logic_count.end()) ||
				(ipreprocc != iter->second->cmplx_preproc_count.end()) ||
				(iassignc != iter->second->cmplx_assign_count.end()) ||
				(ipointerc != iter->second->cmplx_pointer_count.end()) )
		{
			cplxOutputFile << "\n                              TOTAL OCCURRENCES OF " << iter->second->language_name << " COMPLEXITY COUNTS" << endl;               
			cplxOutputFile << "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n";
			cplxOutputFile << "    Math Functions                Trignometric                    Logrithmic                     Calculations                   Conditionals                   Logical                     Preprocessor                     Assignment                  Pointer    \n";
			cplxOutputFile.setf(ios::right);
		}
			
		while (	(imathc != iter->second->math_func_count.end()) || 
				(itrigc != iter->second->trig_func_count.end()) ||
				(ilogc  != iter->second->log_func_count.end()) ||
				(icalcc != iter->second->cmplx_calc_count.end()) ||
				(icondc != iter->second->cmplx_cond_count.end()) ||
				(ilogicc != iter->second->cmplx_logic_count.end()) ||
				(ipreprocc != iter->second->cmplx_preproc_count.end()) ||
				(iassignc != iter->second->cmplx_assign_count.end()) ||
				(ipointerc != iter->second->cmplx_pointer_count.end()) )
		{
			if (imath != iter->second->math_func_list.end())  // imath
			{
				cplxOutputFile << ' ' << *imath << dots.substr(imath->length());
				cplxOutputFile.width(4);
				if (printDuplicates)
					cplxOutputFile << (*imathc).first;
				else
					cplxOutputFile << (*imathc).second;
				imath++;
				imathc++;
			}
			else
			{
				cplxOutputFile << COL_SP;
			}
			cplxOutputFile << SP_BW_COL;

			if (itrig != iter->second->trig_func_list.end())  // itrig
			{
				cplxOutputFile << ' ' << *itrig << dots.substr(itrig->length());
				cplxOutputFile.width(4);
				if (printDuplicates)
					cplxOutputFile << (*itrigc).second;
				else
					cplxOutputFile << (*itrigc).first;
				itrig++;
				itrigc++;
			}
			else
			{
				cplxOutputFile << COL_SP;
			}
			cplxOutputFile << SP_BW_COL;
			
			if (ilog != iter->second->log_func_list.end())   // ilog
			{
				cplxOutputFile << ' ' << *ilog << dots.substr(ilog->length());
				cplxOutputFile.width(4);
				if (printDuplicates)
					cplxOutputFile << (*ilogc).second;
				else
					cplxOutputFile << (*ilogc).first;
				ilog++;
				ilogc++;
			}
			else
			{
				cplxOutputFile << COL_SP;
			}
			cplxOutputFile << SP_BW_COL;

			if (icalc != iter->second->cmplx_calc_list.end())   // icalc
			{
				cplxOutputFile << ' ' << *icalc << dots.substr(icalc->length());
				cplxOutputFile.width(4);
				if (printDuplicates)
					cplxOutputFile << (*icalcc).second;
				else
					cplxOutputFile << (*icalcc).first;
				icalc++;
				icalcc++;
			}
			else
			{
				cplxOutputFile << COL_SP;
			}
			cplxOutputFile << SP_BW_COL;

			if (icond != iter->second->cmplx_cond_list.end())   // icond
			{
				cplxOutputFile << ' ' << *icond << dots.substr(icond->length());
				cplxOutputFile.width(4);
				if (printDuplicates)
					cplxOutputFile << (*icondc).second;
				else
					cplxOutputFile << (*icondc).first;
				icond++;
				icondc++;
			}
			else
			{
				cplxOutputFile << COL_SP;
			}
			cplxOutputFile << SP_BW_COL;

			if (ilogic != iter->second->cmplx_logic_list.end())   // ilogic
			{
				cplxOutputFile << ' ' << *ilogic << dots.substr(ilogic->length());
				cplxOutputFile.width(4);
				if (printDuplicates)
					cplxOutputFile << (*ilogicc).second;
				else
					cplxOutputFile << (*ilogicc).first;
				ilogic++;
				ilogicc++;
			}
			else
			{
				cplxOutputFile << COL_SP;
			}
			cplxOutputFile << SP_BW_COL;

			if (ipreproc != iter->second->cmplx_preproc_list.end())   // ipreproc
			{
				cplxOutputFile << ' ' << *ipreproc << dots.substr(ipreproc->length());
				cplxOutputFile.width(4);
				if (printDuplicates)
					cplxOutputFile << (*ipreprocc).second;
				else
					cplxOutputFile << (*ipreprocc).first;
				ipreproc++;
				ipreprocc++;
			}
			else
			{
				cplxOutputFile << COL_SP;
			}
			cplxOutputFile << SP_BW_COL;

			if (iassign != iter->second->cmplx_assign_list.end())   // ipreproc
			{
				cplxOutputFile << ' ' << *iassign << dots.substr(iassign->length());
				cplxOutputFile.width(4);
				if (printDuplicates)
					cplxOutputFile << (*iassignc).second;
				else
					cplxOutputFile << (*iassignc).first;
				iassign++;
				iassignc++;
			}
			else
			{
				cplxOutputFile << COL_SP;
			}
			cplxOutputFile << SP_BW_COL;
			if (ipointer != iter->second->cmplx_pointer_list.end())   // RST Pointers
			{
				cplxOutputFile << ' ' << *ipointer << dots.substr(ipointer->length());
				cplxOutputFile.width(4);
				if (printDuplicates)
					cplxOutputFile << (*ipointerc).second;
				else
					cplxOutputFile << (*ipointerc).first;
				ipointer++;
				ipointerc++;
			}
			else
			{
				cplxOutputFile << COL_SP;
			}
			cplxOutputFile << endl;
		}
	}

	cplxOutputFile.close();

	return 1;
}

/****************
Prints the duplicate summary output file. 
Shows which files were duplicates, regardless of file name/path.
*****************/
void MainObject::PrintDuplicateSummary(bool useListA, string outputFileNamePrePend)
{
	if (useListA)
	{
		if (duplicateFilesInA2.size() < 1)
			return;
	}
	else
	{
		if (duplicateFilesInB2.size() < 1)
			return;
	}

	SourceFileList* mySourceFile = (useListA) ? &SourceFile : &SourceFileB;

	ofstream dupFile;
	string dupFileName(outputFileNamePrePend);
	dupFileName.append(DUP_PAIRS_OUTFILE);

	dupFile.open(dupFileName.c_str(), ofstream::out);
	if (!dupFile.is_open())
	{
		string err = "Error: Failed to open duplicate file pair summary output file (";
		err += dupFileName;
		err += ")";
		cout << err << endl;
		CUtil::AddError(err);
		return;
	}

	CUtil::PrintFileHeader(dupFile, "DUPLICATE FILE PAIRS");
	dupFile << endl;
	dupFile.setf(ofstream::left);
	dupFile.width(45);
	dupFile << "Original";
	dupFile.unsetf(ofstream::left);
	dupFile.width(5);
	dupFile << "  |  ";
	dupFile.width(3);
	dupFile.setf(ofstream::left);
	dupFile.width(45);
	dupFile << "Duplicate";
	dupFile << endl;
	if (useListA)
		PrintDupList(duplicateFilesInA1, duplicateFilesInA2, dupFile);
	else
		PrintDupList(duplicateFilesInB1, duplicateFilesInB2, dupFile);
	dupFile.close();
}

void MainObject::PrintDupList(StringVector& myList1, StringVector& myList2, ofstream& outfile)
{
	if (myList1.size() > 0)
	{
		for (int y = 0; y < 90; y++)
			outfile << "-";
		outfile << endl;
		StringVector::iterator myI2 = myList2.begin();
		for (StringVector::iterator myI1 = myList1.begin(); myI1 != myList1.end(); myI1++)
		{
			outfile.setf(ofstream::left);
			outfile.width(45);
			outfile << (*myI1);
			outfile.unsetf(ofstream::left);
			outfile.width(5);
			outfile << "  |  ";
			outfile.setf(ofstream::left);
			outfile.width(45);
			outfile << (*myI2) << endl;
			myI2++;
		}
	}
}

/** Finds duplicate files in each baseline and puts them into duplicates lists
*/
void MainObject::findDuplicateFiles(SourceFileList& fileList, StringVector& dupList1, StringVector& dupList2)
{
	for (SourceFileList::iterator i = fileList.begin(); i != fileList.end(); i++)
	{
		if (!(*i).second.duplicate)
		{
			findDuplicateFor(fileList, i, dupList1, dupList2);
		}
	}
	//At this point dupList1 and dupList2 will contain lists of duplicate file pairs
}

// Description: Given a particular SourceFile finds if any are duplicates in the list
// Revision  Date     Author  Modification
// Rev-1     Fall 08  HG      Original author
// Rev-2     Fall 08  VN      Modified the function to make it run a bit faster
bool MainObject::findDuplicateFor(SourceFileList& compareList, SourceFileList::iterator& i,
								  StringVector& dupList1, StringVector& dupList2) {
	bool foundMatch = false;
	SourceFileList::iterator j = i;
	if (j == compareList.end())
	{
		return false;
	}
	for (j++; j != compareList.end(); j++)
	{
		if ((*j).second.duplicate)
			continue;//Already been matched

		if ((*i).first.size() != (*j).first.size() &&
			CUtil::ExtractFilename((*i).second.file_name).compare(CUtil::ExtractFilename((*j).second.file_name)) != 0) // VN: this helps run a bit faster
			continue; //if two files have different number of lines

		// if files have same name, do a diff and mark as duplicates if logical SLOC change % is below threshold
		bool filesmatched;
		if (CUtil::ExtractFilename((*i).second.file_name).compare(CUtil::ExtractFilename((*j).second.file_name)) == 0)
		{
			filesmatched = false;
			
			//Each source file elements results object has a mySLOCLines object with the SLOC to be diffed
			CmpMngr myDiffManager;
			srcLineVector firstFile = (*i).second.mySLOCLines;
			srcLineVector secondFile = (*j).second.mySLOCLines;
			
			//This makes sure that if one of the files was unmatched it will just compare it against an empty set
			myDiffManager.compare(&firstFile, &secondFile, 60);

			double changed_lines, total_lines, pct_change = 0.0;
			changed_lines = myDiffManager.nAddedLines + myDiffManager.nDeletedLines + myDiffManager.nChangedLines;
			if (changed_lines > 0.0)
			{
				total_lines = myDiffManager.nDeletedLines + myDiffManager.nChangedLines + myDiffManager.nNochangedLines;
				pct_change = (changed_lines / total_lines) * 100.0;
			}
			if (pct_change <= duplicate_threshold)
				filesmatched = true;
		}
		else
		{	// If filenames are different, do a line by line comparison for identical duplicate
			vector<lineElement>::iterator baseLine = (*i).first.begin();
			vector<lineElement>::iterator compareLine = (*j).first.begin();
			filesmatched = true;
			while (baseLine != (*i).first.end() && compareLine != (*j).first.end())
			{
				if ((*baseLine).line.compare((*compareLine).line) != 0)
				{
					filesmatched = false;
					break;
				}
				baseLine++;
				compareLine++;
			}
			if (baseLine != (*i).first.end() || compareLine != (*j).first.end())
			{
				filesmatched = false;
			}
		}
		if (filesmatched)
		{
			// Add pair to duplicate list
			(*j).second.duplicate = true;
			dupList1.push_back((*i).second.file_name);
			dupList2.push_back((*j).second.file_name);
			foundMatch = true;
		}
	}
	return foundMatch;
}
